package cn.itcast.user.web;

import cn.itcast.user.pojo.User;
import cn.itcast.user.service.UserService;

import lombok.extern.slf4j.Slf4j;

import org.apache.http.Header;
import org.springframework.beans.factory.annotation.Autowired;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;

@Slf4j
@RestController
@RequestMapping("/user")
@RefreshScope   //配置热更新的注解，相当的繁琐，麻烦
public class UserController {

    @Autowired
    private UserService userService;
//
    @Value("${pattern.dataFormat}")
    private String dataFormat;

    /**
     * 路径： /user/110
     *
     * @param id 用户id
     * @return 用户
     */
    @GetMapping("/{id}")
    public User queryById(@PathVariable("id") Long id) {

        return userService.queryById(id);
    }

//    本地获取本地配置解析当前时间
    @GetMapping("/now")
    public String getDate(){
        System.out.println(dataFormat);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dataFormat);
        Date date = new Date(System.currentTimeMillis());
        String format = simpleDateFormat.format(date);
        return format;
    }
}
